package io.renren.modules.heartself.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.heartself.dao.HeartMovieDao;
import io.renren.modules.heartself.entity.HeartMovieEntity;
import io.renren.modules.heartself.service.HeartMovieService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("heartMovieService")
public class HeartMovieServiceImpl extends ServiceImpl<HeartMovieDao, HeartMovieEntity> implements HeartMovieService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String movieName = (String) params.get("fileName");
        Long userId = Long.parseLong(params.get("userId").toString());
        IPage<HeartMovieEntity> page = this.page(
                new Query<HeartMovieEntity>().getPage(params),
                new QueryWrapper<HeartMovieEntity>().like(StringUtils.isNotBlank(movieName), "file_name", movieName)
                        .eq(userId != null, "user_id", userId)
        );

        return new PageUtils(page);
    }

}